<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='评论管理',active='comments'">
<header th:replace="back/header::headerFragment(${title},${active})"></header>
<head>
    <meta th:name="_csrf" th:content="${_csrf.token}"/>
    <meta th:name="_csrf_header" th:content="${_csrf.headerName}"/>
</head>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="back/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">评论管理</h4>
                    </div>
                    <div class="col-md-12">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th width="25%">评论内容</th>
                                <th width="15%">评论人</th>
                                <th width="20%">所属文章</th>
                                <th>发布时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
<!--                            <th:block th:each="?? : ${comments.list}">-->
<!--                                <tr th:id="??">-->
<!--                                    <td th:text="??"></td>-->
<!--                                    <td th:text="??"></td>-->
<!--                                    <td th:text="??"></td>-->
<!--                                    <td th:text="${commons.dateFormat(??)}"></td>-->
<!--                                    <td>-->
<!--                                        <a th:href="？？？"-->
<!--                                           class="btn btn-primary btn-sm waves-effect waves-light m-b-5">-->
<!--                                            <i class="fa fa-edit"></i> 编辑</a>-->
<!--                                        <a href="javascript:void(0)" th:onclick="'delComment('+${comment.id}+');'"-->
<!--                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5">-->
<!--                                            <i class="fa fa-trash-o"></i> 删除</a>-->
<!--                                        &lt;!&ndash;预览功能保持不变，如果需要特定预览页可以修改链接-->
<!--                                        <a th:href="？？？？" target="_blank"&ndash;&gt;-->
<!--                                           class="btn btn-warning btn-sm waves-effect waves-light m-b-5">-->
<!--                                            <i class="fa fa-eye"></i> 预览</a>-->
<!--                                    </td>-->
<!--                                </tr>-->
                            </th:block>
                            </tbody>
                        </table>
                        <!-- 修正分页组件调用方式 -->
                        <div th:replace="comm/paging :: pageAdminNav(${comments})"></div>
                    </div>
                </div>
                <div th:replace="back/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="back/footer :: footer"></div>
<script type="text/javascript">
    function delComment(id) {
        var token = $("meta[name='_csrf']").attr("content");
        var header = $("meta[name='_csrf_header']").attr("content");
        if (confirm('确定删除该评论吗?')) {
            $.ajax({
                type: 'post',
                url: '/admin/comment/delete', // Ensure this matches the AdminController mapping
                data: {id: id},
                dataType: 'json',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader(header, token);
                },
                success: function (result) {
                    if (result && result.success) {
                        alert("评论删除成功");
                        window.location.reload();
                    } else {
                        alert(result.msg || '评论删除失败');
                    }
                }
            });
        }
    }
</script>
</body>
</html>